package com.kehao.leetcode.jzoffer;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Kehao.Chen
 * @version 1.0
 * @date 2022/6/29 15:20
 */
public class JZSolution041 {

    private static class MovingAverage {

        private List<Integer> list;
        private int size;
        private int count;

        /** Initialize your data structure here. */
        public MovingAverage(int size) {
            this.list = new LinkedList<Integer>();
            this.size = size;
        }

        public double next(int val) {
            this.list.add(val);
            count += val;
            if(list.size()>size){
                Integer remove = list.remove(0);
                count -= remove;
            }
            return (count+0.0)/this.list.size();
        }
    }
}
